package com.hangzhou.welbeing.welbeinginstrument.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.bean.WeChatMallBeanDate;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 杭州惟君医疗科技有限公司14
 * Created by 20433 on 2018/1/30
 */

public class SelectedRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener {
    private Context mContext;
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private List<WeChatMallBeanDate.DataBean> mlist = new ArrayList();

    public SelectedRecyclerAdapter(Context paramContext) {
        this.mContext = paramContext;
    }

    public void addItem(List<WeChatMallBeanDate.DataBean> paramList) {
        this.mlist.addAll(paramList);
        notifyDataSetChanged();
    }

    public int getItemCount() {
        return this.mlist.size();
    }

    public void onBindViewHolder(RecyclerView.ViewHolder paramViewHolder, int paramInt) {
        SelectedRecyclerHolder viewHolder = (SelectedRecyclerHolder) paramViewHolder;
        Glide.with(this.mContext).load("http://oop.welbeing.cn/Public/Uploads/" + mlist.get(paramInt).url).placeholder(R.mipmap.phon_editing).error(R.mipmap.phon_editing).crossFade().into(viewHolder.iv_picter);
    }

    public void onClick(View paramView) {
        if (this.mOnItemClickListener != null) {
            this.mOnItemClickListener.onItemClick(paramView);
        }
    }

    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup paramViewGroup, int paramInt) {
        View view = View.inflate(this.mContext, R.layout.item_selected_recycler, null);
        SelectedRecyclerHolder selectedRecyclerHolder = new SelectedRecyclerHolder(view);
        view.setOnClickListener(this);
        return selectedRecyclerHolder;
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener paramOnRecyclerViewItemClickListener) {
        this.mOnItemClickListener = paramOnRecyclerViewItemClickListener;
    }

    public class SelectedRecyclerHolder
            extends RecyclerView.ViewHolder {
        private final ImageView iv_picter;

        public SelectedRecyclerHolder(View paramView) {
            super(paramView);
            this.iv_picter = ((ImageView) paramView.findViewById(R.id.item_selected_recycler_iv_picter));
        }
    }
}
